<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-menu-add">
			<input id="treeId" name="pid" type="hidden" th:value="${wechatShopProductCategory.id}" />
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级类目：</label>
				<div class="col-sm-8">
				    <div class="input-group">
					    <input class="form-control" type="text" onclick="selectMenuTree()" id="treeName" readonly="true" th:value="${wechatShopProductCategory.name}">
				        <span class="input-group-addon"><i class="fa fa-search"></i></span>
				    </div>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">类目名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="name" id="name" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">栏目状态:</label>
				<div class="col-sm-8">
					<label class="checkbox-inline i-checks"> <input type="radio" name="status" value="0" checked="checked"/> 启用</label> 
					<label class="checkbox-inline i-checks"> <input type="radio" name="status" value="1" /> 禁用</label> 
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	 <script>
        var prefix = ctx + "wechat/wechatShopProductCategory";
        
        $("#form-menu-add").validate({
        	rules:{
        		name:{
        			remote: {
                        url: prefix + "/checkChannelNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"name" : function() {
                                return $.common.trim($("#name").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		orders:{
        			digits:true
        		},
        	},
        	messages: {
                "name": {
                    remote: "类目已经存在"
                }
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-menu-add').serialize());
	        }
	    }

    

        /*菜单管理-新增-选择菜单树*/
        function selectMenuTree() {
        	var treeId = $("#treeId").val();
        	var id = treeId > 0 ? treeId : 1;
        	var url = prefix + "/selectChannelTree/" + id;
			var options = {
				title: '类目选择',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}
    </script>
</body>
</html>
